
//
//  filtrateView.m
//  PTravel
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "filtrateView.h"

@implementation filtrateView

- (void)dealloc
{
    [_sliderView release];
    [_locationButton release];
    [_travelButton release];
    [_filrateLabel release];
    [_OKBtn release];
    [_myTableView release];
    [_locationArr release];
    [_timeArr release];
    [_locationValueArr release];
    [_timeValueArr release];
    [_time release];
    [_location release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)changColor
{
    self.backgroundColor = CELLCOLOR;
    self.myTableView.backgroundColor = CELLCOLOR;
    [self.locationButton setBackgroundColor:CELLCOLOR];
    self.travelButton.backgroundColor = CELLCOLOR;
}

- (void)createSubViews
{
    
    
    self.isTime = NO;
    self.backgroundColor = CELLCOLOR;
    

    
    self.sliderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, BOUNDS.size.width, 50)];
    self.sliderView.backgroundColor = [UIColor colorWithWhite:0.809 alpha:1.000];
    [self addSubview:self.sliderView];
    [_sliderView release];
    
    self.filrateLabel  = [[UILabel alloc] initWithFrame:CGRectMake(BOUNDS.size.width/2-30, 0, 60, 50)];
    self.filrateLabel.text = @"筛选";
    self.filrateLabel.textColor = [UIColor blackColor];
    self.filrateLabel.textAlignment = 1;
    [self.sliderView addSubview:self.filrateLabel];
    [_filrateLabel release];
    
    self.OKBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.OKBtn.frame = CGRectMake(BOUNDS.size.width-50, 0, 50, 50);
    [self.OKBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.OKBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [self.OKBtn addTarget:self action:@selector(OKBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.sliderView addSubview:self.OKBtn];
    
    
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(120, 50, BOUNDS.size.height-120, BOUNDS.size.height/2-45) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.bounces = NO;
    self.myTableView.backgroundColor = CELLCOLOR;
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self addSubview:self.myTableView];
    [_myTableView release];
    
    
    self.locationArr = [NSMutableArray arrayWithObjects:@"全部", @"北京/天津", @"上海/杭州", @"成都/重庆", @"广州/深圳", @"港澳台", @"国内其他", @"海外", nil];
    self.timeArr = [NSMutableArray arrayWithObjects:@"全部", @"1个月内", @"1-3个月", @"3-6个月", @"6个月以后", @"", @"", nil];
    
    self.locationValueArr = [NSMutableArray arrayWithObjects:@"", @"bjtj", @"shhz", @"cdcq", @"gzsz", @"hmt", @"inland", @"abroad", nil];
    self.timeValueArr = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"5", @"5", nil];
    
    
    self.locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.locationButton.frame = CGRectMake(0, 50, 120, 42);
    [self.locationButton setTitle:@"出发地" forState:UIControlStateNormal];
    [self.locationButton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
    [self.locationButton setBackgroundColor:CELLCOLOR];
    [self.locationButton addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.locationButton];
    
    self.travelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.travelButton.frame = CGRectMake(0, 92, 120, 42);
    [self.travelButton setTitle:@"旅行时间" forState:UIControlStateNormal];
    [self.travelButton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
    self.travelButton.backgroundColor = CELLCOLOR;
    [self.travelButton addTarget:self action:@selector(travelAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.travelButton];
    
    

}

- (void)OKBtnAction
{
    [self.filtrateViewDelegate okBtn];
}

- (void)locationAction
{
    [self.locationButton setBackgroundColor:[UIColor colorWithWhite:0.698 alpha:1.000]];
    [self.travelButton setBackgroundColor:[UIColor whiteColor]];
    self.isTime = NO;
    [self.myTableView reloadData];
}

- (void)travelAction
{
    [self.travelButton setBackgroundColor:[UIColor colorWithWhite:0.698 alpha:1.000]];
    [self.locationButton setBackgroundColor:[UIColor whiteColor]];
    self.isTime = YES;
    [self.myTableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.isTime == NO) {
        return self.locationArr.count;
    }else{
        return  self.timeArr.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    if (self.isTime == NO) {
        cell.textLabel.text = [self.locationArr objectAtIndex:indexPath.row];
    }else{
        cell.textLabel.text = [self.timeArr objectAtIndex:indexPath.row];
    }
    cell.textLabel.textColor = TEXTCOLOR;
    cell.backgroundColor = CELLCOLOR;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"---------------------------------------");
    if (self.isTime == NO) {
        self.location = [self.locationValueArr objectAtIndex:indexPath.row];
        
    }else{
        self.time  = [self.timeValueArr objectAtIndex:indexPath.row];
        
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
